<style>
/*body{*/
/*  background-image: url('src/assets/images/loginbg.jpg');*/
/*  background-size: cover;*/
/*}*/
#app{
  margin-left: 30%;
}
.center {
  background: url("../../assets/images/loginbg.jpg") no-repeat center center;
  height: 100%;
  width: 100%;
  background-size: cover;
  position: absolute;
  left: 0;
  top: 0;
  /*width: 1920px;*/
  /*height: 1080px;*/
  /*background-image: url('../../assets/images/loginbg.jpg');*/
  /*background-size: initial;*/
  /*background-repeat: no-repeat;*/
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

h1 {
  font-size: 30px;
  color: black;
}

.logon {
  background-color: #fff;
  border-radius: 10px;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
  /* position: relative;
  overflow: hidden; */
  width: 768px;
  max-width: 100%;
  min-height: 480px;
  margin-top: 20px;
  display: flex;
  background: -webkit-linear-gradient(right, #4284db, #29eac4);
}

.overlaylong {
  border-radius: 10px 0 0 10px;
  width: 50%;
  height: 100%;
  background-color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlaylongleft {
  border-radius: 0px 10px 10px 0px;
  width: 50%;
  height: 100%;
  background-color: #fff;
  transform: translateX(100%);
  transition: transform 0.6s ease-in-out;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlaylongright {
  border-radius: 10px 0 0 10px;
  width: 50%;
  height: 100%;
  background-color: #fff;
  transform: translateX(0%);
  transition: transform 0.6s ease-in-out;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlaytitle {
  border-radius: 0px 10px 10px 0px;
  width: 50%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0);
  display: flex;
  align-items: center;
  justify-content: center;
}


.overlaytitleH2 {
  font-size: 30px;
  color: #fff;
  margin-top: 20px;
}

.overlaytitleP {
  font-size: 15px;
  color: #fff;
  margin-top: 20px;
}

.overlaytitleleft {
  border-radius: 0px 10px 10px 0px;
  width: 50%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateX(0%);
  transition: transform 0.6s ease-in-out;
}

.overlaytitleright {
  border-radius: 0px 10px 10px 0px;
  width: 50%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateX(-100%);
  transition: transform 0.6s ease-in-out;
}

.overlaytitle-Signin {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.overlaytitle-Signup {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.buttongohs {
  width: 180px;
  height: 40px;
  border-radius: 50px;
  border: 1px solid #fff;
  color: #fff;
  font-size: 15px;
  text-align: center;
  line-height: 40px;
  margin-top: 40px;
}

.overlaylongH2 {
  font-size: 25px;
  color: black;
  /* width: 250px; */
}

.overlaylong-Signin {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.overlaylong-Signup {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

input {
  background-color: #eee;
  border: none;
  padding: 12px 15px;
  margin: 10px 0;
  width: 240px;
}
h3{
  font-size: 10px;
  margin-top: 10px;
  cursor: pointer;
}
.inupbutton{
  background-color: #29eac4;
  border: none;
  width: 180px;
  height: 40px;
  border-radius: 50px;
  font-size: 15px;
  color: #fff;
  text-align: center;
  line-height: 40px;
  margin-top: 30px;
}
</style>

<template>
  <div class="center">
    <h1>Sign in/ Sign up</h1>
    <div class="logon">
      <div :class="overlaylong">
        <div class="overlaylong-Signin" v-if="disfiex == 0">
          <h2 class="overlaylongH2">Sign in</h2>
          <input type="text" placeholder="user" v-model="username">
          <input type="text" placeholder="password" v-model="password">
          <h3>Forgot your password?</h3>
          <el-button @click="login" class="inupbutton">Sign in</el-button>
        </div>
        <div class="overlaylong-Signup" v-if="disfiex == 1">
          <h2 class="overlaylongH2">Registered Account</h2>
          <input type="text" placeholder="user" v-model="username">
          <input type="text" placeholder="password" v-model="password">
          <el-button @click="regist" class="inupbutton">Sign up</el-button>
        </div>

      </div>
      <div :class="overlaytitle">
        <div class="overlaytitle-Signin" v-if="disfiex == 0">
          <h2 class="overlaytitleH2">Hello,Friend!</h2>
          <p class="overlaytitleP">
            Enter your personal details and start journey with us
          </p>
          <div class="buttongohs" @click="Signin">Sign up</div>
        </div>
        <div class="overlaytitle-Signup" v-if="disfiex == 1">
          <h2 class="overlaytitleH2">Welcome Back!</h2>
          <p class="overlaytitleP">To keep connected with us please login with your personal info</p>
          <div class="buttongohs" @click="Signup">Sign in</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>

import {toRefs, ref, reactive, } from 'vue'

import { useRouter } from 'vue-router';
import {postUserInfo} from "../../api/user"

// import axios from "axios";

export default {
  setup(){

//表单
    const formDataRef = ref();
    let formData = reactive({
      username: "",
      password: "",
      overlaylong: 'overlaylong',
      overlaytitle: 'overlaytitle',
      disfiex: 0,
    });
    const rules = {
      username: [{
        required: true,
        message: "请输入用户名"
      }],
      password: [{
        required: true,
        message: "请输入密码"
      }],
      // checkCode: [{
      //     required: true,
      //     message: "请输入验证码"
      // }],
    }

    const router = useRouter();

    const login = () =>{
      console.log(formData.username,formData.password)
      postUserInfo(
      // axios.post("/api/vue/vite/login",
          {
            "username": formData.username,
            "password":formData.password
          }).then((res)=>{
        console.log(res.data)
        if(res.code === 200){
          router.push('/register')
        }else {
          alert(res.msg)
        }

      }).catch((err)=>{
        console.log("1111:",err)
      })

    }

    const regist =()=>{
      console.log(formData.username,formData.password)
    }
    const Signin=()=> {
      formData.overlaylong = "overlaylongleft"
      formData.overlaytitle = "overlaytitleright"
      setTimeout(() => {
        formData.disfiex = 1
      }, 200)
    }
    const Signup=()=>{
      formData.overlaylong = "overlaylongright"
      formData.overlaytitle = "overlaytitleleft"

      setTimeout(() => {
        formData.disfiex = 0
      }, 200)

    }

    return ({
      // overlaylong: 'overlaylong',
      // overlaytitle: 'overlaytitle',
      // disfiex: 0,
      login,
      regist,
      Signin,
      Signup,
      ...toRefs(formData),
    })
  }
}
</script>